home *** CD-ROM | disk | FTP | other *** search
/ All for Cell Phones: Sony Ericsson / Sony-Ericsson 2004.iso / Java / CostManager / CostManager.jar / CostManager$CostManagerEngine.class (.txt) < prev    next >
Encoding:
Java Class File  |  2001-09-04  |  5.3 KB  |  134 lines

  1. import java.util.Hashtable;
  2. import java.util.Vector;
  3. import javax.microedition.lcdui.Image;
  4. import javax.microedition.rms.RecordComparator;
  5. import javax.microedition.rms.RecordEnumeration;
  6. import javax.microedition.rms.RecordFilter;
  7. import javax.microedition.rms.RecordStore;
  8.  
  9. class CostManager$CostManagerEngine {
  10.    private RecordStore typesRS;
  11.    private RecordStore costsRS;
  12.    private Vector typesVec;
  13.    // $FF: synthetic field
  14.    private final CostManager this$0;
  15.  
  16.    CostManager$CostManagerEngine(CostManager this$0) throws Exception {
  17.       this.this$0 = this$0;
  18.       this.typesRS = RecordStore.openRecordStore("typesRS", true);
  19.       this.costsRS = RecordStore.openRecordStore("costsRS", true);
  20.       this.typesVec = new Vector();
  21.       this.initTypesVec();
  22.       this.updateTypesArray();
  23.    }
  24.  
  25.    Hashtable getCosts() {
  26.       Hashtable mapy = new Hashtable();
  27.       RecordEnumeration enum = null;
  28.       Cost tempCost = null;
  29.       String typeName = null;
  30.       int typeIndex = 0;
  31.       int typeTotalSum = 0;
  32.  
  33.       try {
  34.          enum = this.costsRS.enumerateRecords((RecordFilter)null, (RecordComparator)null, false);
  35.          int tempId = 0;
  36.          int tempSum = 0;
  37.          long tempTime = 0L;
  38.          long min = CostManager.access$000(this.this$0).getDate().getTime();
  39.          long max = CostManager.access$100(this.this$0).getDate().getTime() + 86400000L;
  40.  
  41.          while(enum.hasNextElement()) {
  42.             tempId = enum.nextRecordId();
  43.             byte[] data = this.costsRS.getRecord(tempId);
  44.             tempCost = new Cost(data);
  45.             tempSum = tempCost.getSum();
  46.             typeName = tempCost.getType();
  47.             tempTime = tempCost.getTime();
  48.             if (tempTime >= min && tempTime <= max) {
  49.                if (mapy.containsKey(typeName)) {
  50.                   System.out.println("add to report : " + tempCost);
  51.                   mapy.put(typeName, new Integer((Integer)mapy.get(typeName) + tempSum));
  52.                } else {
  53.                   System.out.println("(first)add to report : " + tempCost);
  54.                   mapy.put(typeName, new Integer(tempCost.getSum()));
  55.                }
  56.             } else {
  57.                System.out.println("not pass the time condition");
  58.             }
  59.          }
  60.       } catch (Exception var16) {
  61.          ((Throwable)var16).printStackTrace();
  62.       }
  63.  
  64.       return mapy;
  65.    }
  66.  
  67.    void delAllCosts() throws Exception {
  68.       System.out.println("within delAllCosts()");
  69.       this.costsRS.closeRecordStore();
  70.       RecordStore.deleteRecordStore("costsRS");
  71.       this.costsRS = RecordStore.openRecordStore("costsRS", true);
  72.    }
  73.  
  74.    void addCost(Cost newCost) throws Exception {
  75.       byte[] vec = newCost.toBytes();
  76.       this.costsRS.addRecord(vec, 0, vec.length);
  77.    }
  78.  
  79.    void updateTypesArray() {
  80.       String[] vec = new String[this.typesVec.size()];
  81.  
  82.       for(int i = 0; i < vec.length; ++i) {
  83.          vec[i] = ((Type)this.typesVec.elementAt(i)).getName();
  84.       }
  85.  
  86.       CostManager.access$202(this.this$0, vec);
  87.    }
  88.  
  89.    void initTypesVec() {
  90.       RecordEnumeration enum = null;
  91.  
  92.       try {
  93.          enum = this.typesRS.enumerateRecords((RecordFilter)null, (RecordComparator)null, false);
  94.          int tempId = 0;
  95.  
  96.          while(enum.hasNextElement()) {
  97.             tempId = enum.nextRecordId();
  98.             byte[] data = this.typesRS.getRecord(tempId);
  99.             this.typesVec.addElement(new Type(data));
  100.          }
  101.       } catch (Exception var4) {
  102.          ((Throwable)var4).printStackTrace();
  103.       }
  104.  
  105.    }
  106.  
  107.    void addType(Type type) throws Exception {
  108.       byte[] temp = type.toBytes();
  109.       int idTemp = this.typesRS.addRecord(temp, 0, temp.length);
  110.       type.setId(idTemp);
  111.       this.typesVec.addElement(type);
  112.       CostManager.access$300(this.this$0).append(type.getName(), (Image)null);
  113.       CostManager.access$400(this.this$0).append(type.getName(), (Image)null);
  114.    }
  115.  
  116.    void removeTypeByName(String str) {
  117.       int recordId = 0;
  118.  
  119.       for(int i = 0; i < this.typesVec.size(); ++i) {
  120.          System.out.println("i=" + i);
  121.          if (((Type)this.typesVec.elementAt(i)).getName().equals(str)) {
  122.             recordId = i;
  123.          }
  124.       }
  125.  
  126.       try {
  127.          this.typesRS.deleteRecord(recordId);
  128.       } catch (Exception var5) {
  129.          ((Throwable)var5).printStackTrace();
  130.       }
  131.  
  132.    }
  133. }
  134.